package insigne.kernel.sgbdinterface.basics;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class Composition extends DBOperator{

	/* ############################### Fields ############################### */
	private Commande IDCommande;

	private Listeinsignes IDListe;

	/* ############################### Getters ############################## */
	public Commande getIDCommande(){
		return IDCommande;
	}

	public Listeinsignes getIDListe(){
		return IDListe;
	}

	/* ############################### Setters ############################## */
	public void setIDCommande(Commande newValue){
		this.IDCommande = newValue;
	}

	public void setIDListe(Listeinsignes newValue){
		this.IDListe = newValue;
	}

	/* ########################### CLASS CONSTRUCTORS ####################### */
	public Composition(){
		
	}
	
	public Composition(int IDCommande,int IDListe, boolean toBeInserted) throws SQLException {
		openConnection();
		this.IDCommande = new Commande(IDCommande);
		this.IDListe = new Listeinsignes(IDListe);
		if (toBeInserted) {
			executeUpdate("INSERT INTO composition VALUES('" + IDCommande
					+ "','" + IDListe + "')");
		}
		con.close();
	}
	
	public ArrayList<Listeinsignes> getListes(int IDCommande) throws SQLException{
		openConnection();
		ArrayList<Listeinsignes> res = new ArrayList<Listeinsignes>();
		ResultSet rs = executeSelect("SELECT * FROM composition WHERE IDCommande='" + IDCommande + "'");
		while(rs.next()){
			res.add(new Listeinsignes(rs.getInt("IDListe")));
		}
		con.close();
		return res;
	}
}